<!DOCTYPE html>
<html lang="en-us">
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    
<meta charset="UTF-8">
<title>significant_terms Demo | Elasticsearch: The Definitive Guide [2.x] | Elastic</title>
<link rel="home" href="index.html" title="Elasticsearch: The Definitive Guide [2.x]">
<link rel="up" href="significant-terms.html" title="Significant Terms">
<link rel="prev" href="significant-terms.html" title="Significant Terms">
<link rel="next" href="docvalues-and-fielddata.html" title="Doc Values and Fielddata">
<meta name="DC.type" content="Learn/Docs/Legacy/Elasticsearch/Definitive Guide/2.x">
<meta name="DC.subject" content="Elasticsearch">
<meta name="DC.identifier" content="2.x">
<meta name="robots" content="noindex,nofollow">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://cdn.optimizely.com/js/18132920325.js"></script>
    <link rel="apple-touch-icon" sizes="57x57" href="/apple-icon-57x57.png">
    <link rel="apple-touch-icon" sizes="60x60" href="/apple-icon-60x60.png">
    <link rel="apple-touch-icon" sizes="72x72" href="/apple-icon-72x72.png">
    <link rel="apple-touch-icon" sizes="76x76" href="/apple-icon-76x76.png">
    <link rel="apple-touch-icon" sizes="114x114" href="/apple-icon-114x114.png">
    <link rel="apple-touch-icon" sizes="120x120" href="/apple-icon-120x120.png">
    <link rel="apple-touch-icon" sizes="144x144" href="/apple-icon-144x144.png">
    <link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png">
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png">
    <link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32">
    <link rel="icon" type="image/png" href="/android-chrome-192x192.png" sizes="192x192">
    <link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96">
    <link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">
    <link rel="manifest" href="/manifest.json">
    <meta name="apple-mobile-web-app-title" content="Elastic">
    <meta name="application-name" content="Elastic">
    <meta name="msapplication-TileColor" content="#ffffff">
    <meta name="msapplication-TileImage" content="/mstile-144x144.png">
    <meta name="theme-color" content="#ffffff">
    <meta name="naver-site-verification" content="936882c1853b701b3cef3721758d80535413dbfd">
    <meta name="yandex-verification" content="d8a47e95d0972434">
    <meta name="localized" content="true">
    <meta name="st:robots" content="follow,index">
    <meta property="og:image" content="https://www.elastic.co/static/images/elastic-logo-200.png">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
    <link rel="icon" href="/favicon.ico" type="image/x-icon">
    <link rel="apple-touch-icon-precomposed" sizes="64x64" href="/favicon_64x64_16bit.png">
    <link rel="apple-touch-icon-precomposed" sizes="32x32" href="/favicon_32x32.png">
    <link rel="apple-touch-icon-precomposed" sizes="16x16" href="/favicon_16x16.png">
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="/guide/static/styles.css">
  </head>

  <!--© 2015-2021 Elasticsearch B.V. Copying, publishing and/or distributing without written permission is strictly prohibited.-->

  <body>
    <!-- Google Tag Manager -->
    <script>dataLayer = [];</script><noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-58RLH5" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-58RLH5');</script>
    <!-- End Google Tag Manager -->

    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-12395217-16"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      gtag('config', 'UA-12395217-16');
    </script>

    <!--BEGIN QUALTRICS WEBSITE FEEDBACK SNIPPET-->
    <script type="text/javascript">
      (function(){var g=function(e,h,f,g){
      this.get=function(a){for(var a=a+"=",c=document.cookie.split(";"),b=0,e=c.length;b<e;b++){for(var d=c[b];" "==d.charAt(0);)d=d.substring(1,d.length);if(0==d.indexOf(a))return d.substring(a.length,d.length)}return null};
      this.set=function(a,c){var b="",b=new Date;b.setTime(b.getTime()+6048E5);b="; expires="+b.toGMTString();document.cookie=a+"="+c+b+"; path=/; "};
      this.check=function(){var a=this.get(f);if(a)a=a.split(":");else if(100!=e)"v"==h&&(e=Math.random()>=e/100?0:100),a=[h,e,0],this.set(f,a.join(":"));else return!0;var c=a[1];if(100==c)return!0;switch(a[0]){case "v":return!1;case "r":return c=a[2]%Math.floor(100/c),a[2]++,this.set(f,a.join(":")),!c}return!0};
      this.go=function(){if(this.check()){var a=document.createElement("script");a.type="text/javascript";a.src=g;document.body&&document.body.appendChild(a)}};
      this.start=function(){var a=this;window.addEventListener?window.addEventListener("load",function(){a.go()},!1):window.attachEvent&&window.attachEvent("onload",function(){a.go()})}};
      try{(new g(100,"r","QSI_S_ZN_emkP0oSe9Qrn7kF","https://znemkp0ose9qrn7kf-elastic.siteintercept.qualtrics.com/WRSiteInterceptEngine/?Q_ZID=ZN_emkP0oSe9Qrn7kF")).start()}catch(i){}})();
    </script><div id="ZN_emkP0oSe9Qrn7kF"><!--DO NOT REMOVE-CONTENTS PLACED HERE--></div>
    <!--END WEBSITE FEEDBACK SNIPPET-->

    <div id="elastic-nav" style="display:none;"></div>
    <script src="https://www.elastic.co/elastic-nav.js"></script>

    <!-- Subnav -->
    <div>
      <div>
        <div class="tertiary-nav d-none d-md-block">
          <div class="container">
            <div class="p-t-b-15 d-flex justify-content-between nav-container">
              <div class="breadcrum-wrapper"><span><a href="/guide/" style="font-size: 14px; font-weight: 600; color: #000;">Docs</a></span></div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="main-container">
      <section id="content">
        <div class="content-wrapper">

          <section id="guide" lang="en">
            <div class="container">
              <div class="row">
                <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                  <!-- start body -->
                  <div class="page_header">
<p>
  <strong>WARNING</strong>: The 2.x versions of Elasticsearch have passed their
  <a href="https://www.elastic.co/support/eol">EOL dates</a>. If you are running
  a 2.x version, we strongly advise you to upgrade.
</p>
<p>
  This documentation is no longer maintained and may be removed. For the latest
  information, see the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html">current
  Elasticsearch documentation</a>.
</p>
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch: The Definitive Guide [2.x]</a></span>
»
<span class="breadcrumb-link"><a href="aggregations.html">Aggregations</a></span>
»
<span class="breadcrumb-link"><a href="significant-terms.html">Significant Terms</a></span>
»
<span class="breadcrumb-node">significant_terms Demo</span>
</div>
<div class="navheader">
<span class="prev">
<a href="significant-terms.html">« Significant Terms</a>
</span>
<span class="next">
<a href="docvalues-and-fielddata.html">Doc Values and Fielddata »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="_significant_terms_demo"></a>significant_terms Demo<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch-definitive-guide/edit/2.x/300_Aggregations/75_sigterms.asciidoc">edit</a>
</h2>
</div></div></div>
<p>Because the <code class="literal">significant_terms</code> aggregation works by analyzing
statistics, you need to have a certain threshold of data for it to become effective.
That means we won’t be able to index a small amount of example data for the demo.</p>
<p>Instead, we prepared a dataset that contains about 80,000 documents and saved it
as a snapshot in our public demo repository.  To "restore"
this dataset into your cluster:</p>
<div class="olist orderedlist">
<ol class="orderedlist">
<li class="listitem">
<p>Add the following setting to your <code class="literal">elasticsearch.yml</code> configuration file to
whitelist the Elastic demo repository:</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">repositories.url.allowed_urls: ["http://download.elastic.co/*"]</pre>
</div>
</li>
<li class="listitem">
Restart Elasticsearch.
</li>
<li class="listitem">
<p>Run the following snapshot commands. (For more information about using
snapshots, see <a class="xref" href="backing-up-your-cluster.html" title="Backing Up Your Cluster">Backing Up Your Cluster</a>.)</p>
<div class="pre_wrapper lang-sense">
<pre class="programlisting prettyprint lang-sense">PUT /_snapshot/sigterms <a id="CO210-1"></a><i class="conum" data-value="1"></i>
{
    "type": "url",
    "settings": {
        "url": "http://download.elastic.co/definitiveguide/sigterms_demo/"
    }
}

GET /_snapshot/sigterms/_all <a id="CO210-2"></a><i class="conum" data-value="2"></i>

POST /_snapshot/sigterms/snapshot/_restore <a id="CO210-3"></a><i class="conum" data-value="3"></i>

GET /mlmovies,mlratings/_recovery <a id="CO210-4"></a><i class="conum" data-value="4"></i></pre>
</div>
<div class="sense_widget" data-snippet="snippets/300_Aggregations/75_sigterms.json"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO210-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>Register a new read-only URL repository pointing at the demo snapshot</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO210-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>(Optional) Inspect the repository to learn details about available snapshots</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO210-3"><i class="conum" data-value="3"></i></a></p>
</td>
<td align="left" valign="top">
<p>Begin the Restore process.  This will download two indices into your cluster: <code class="literal">mlmovies</code>
and <code class="literal">mlratings</code></p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO210-4"><i class="conum" data-value="4"></i></a></p>
</td>
<td align="left" valign="top">
<p>(Optional) Monitor the Restore process using the Recovery API</p>
</td>
</tr>
</table>
</div>
</li>
</ol>
</div>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>The dataset is around 50 MB and may take some time to download.</p>
</div>
</div>
<p>In this demo, we are going to look at movie ratings by users of MovieLens.  At
MovieLens, users make movie recommendations so other users can find new
movies to watch.  For this demo, we are going to recommend movies by using <code class="literal">significant_terms</code>
based on an input movie.</p>
<p>Let’s take a look at some sample data, to get a feel for what we are working with.
There are two indices in this dataset, <code class="literal">mlmovies</code> and <code class="literal">mlratings</code>.  Let’s look
at <code class="literal">mlmovies</code> first:</p>
<div class="pre_wrapper lang-sense">
<pre class="programlisting prettyprint lang-sense">GET mlmovies/_search <a id="CO211-1"></a><i class="conum" data-value="1"></i>

{
   "took": 4,
   "timed_out": false,
   "_shards": {...},
   "hits": {
      "total": 10681,
      "max_score": 1,
      "hits": [
         {
            "_index": "mlmovies",
            "_type": "mlmovie",
            "_id": "2",
            "_score": 1,
            "_source": {
               "offset": 2,
               "bytes": 34,
               "title": "Jumanji (1995)"
            }
         },
         ....</pre>
</div>
<div class="sense_widget" data-snippet="snippets/300_Aggregations/75_sigterms.json"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO211-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>Execute a search without a query, so that we can see a random sampling of docs.</p>
</td>
</tr>
</table>
</div>
<p>Each document in <code class="literal">mlmovies</code> represents a single movie.  The two important pieces
of data are the <code class="literal">_id</code> of the movie and the <code class="literal">title</code> of the movie.  You can ignore
<code class="literal">offset</code> and <code class="literal">bytes</code>; they are artifacts of the process used to extract this
data from the original CSV files. There are 10,681 movies in this dataset.</p>
<p>Now let’s look at <code class="literal">mlratings</code>:</p>
<div class="pre_wrapper lang-sense">
<pre class="programlisting prettyprint lang-sense">GET mlratings/_search

{
   "took": 3,
   "timed_out": false,
   "_shards": {...},
   "hits": {
      "total": 69796,
      "max_score": 1,
      "hits": [
         {
            "_index": "mlratings",
            "_type": "mlrating",
            "_id": "00IC-2jDQFiQkpD6vhbFYA",
            "_score": 1,
            "_source": {
               "offset": 1,
               "bytes": 108,
               "movie": [122,185,231,292,
                  316,329,355,356,362,364,370,377,420,
                  466,480,520,539,586,588,589,594,616
               ],
               "user": 1
            }
         },
         ...</pre>
</div>
<div class="sense_widget" data-snippet="snippets/300_Aggregations/75_sigterms.json"></div>
<p>Here we can see the recommendations of individual users.  Each document represents
a single user, denoted by the <code class="literal">user</code> ID field.  The <code class="literal">movie</code> field holds a list
of movies that this user watched and recommended.</p>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="_recommending_based_on_popularity"></a>Recommending Based on Popularity<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch-definitive-guide/edit/2.x/300_Aggregations/75_sigterms.asciidoc">edit</a>
</h3>
</div></div></div>
<p>The first strategy we could take is trying to recommend movies based on popularity.
Given a particular movie, we find all users who recommended that movie.  Then
we aggregate all their recommendations and take the top five most popular.</p>
<p>We can express that easily with a <code class="literal">terms</code> aggregation and some filtering.  Let’s
look at <em>Talladega Nights</em>, a comedy about NASCAR racing starring
Will Ferrell.  Ideally, our recommender should find other comedies in a similar
style (and more than likely also starring Will Ferrell).</p>
<p>First we need to find the <em>Talladega Nights</em> ID:</p>
<div class="pre_wrapper lang-sense">
<pre class="programlisting prettyprint lang-sense">GET mlmovies/_search
{
  "query": {
    "match": {
      "title": "Talladega Nights"
    }
  }
}

    ...
    "hits": [
     {
        "_index": "mlmovies",
        "_type": "mlmovie",
        "_id": "46970", <a id="CO212-1"></a><i class="conum" data-value="1"></i>
        "_score": 3.658795,
        "_source": {
           "offset": 9575,
           "bytes": 74,
           "title": "Talladega Nights: The Ballad of Ricky Bobby (2006)"
        }
     },
    ...</pre>
</div>
<div class="sense_widget" data-snippet="snippets/300_Aggregations/75_sigterms.json"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO212-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p><em>Talladega Nights</em> is ID <code class="literal">46970</code>.</p>
</td>
</tr>
</table>
</div>
<p>Armed with the ID, we can now filter the ratings and apply our <code class="literal">terms</code> aggregation
to find the most popular movies from people who also like <em>Talladega Nights</em>:</p>
<div class="pre_wrapper lang-sense">
<pre class="programlisting prettyprint lang-sense">GET mlratings/_search
{
  "size" : 0, <a id="CO213-1"></a><i class="conum" data-value="1"></i>
  "query": {
    "filtered": {
      "filter": {
        "term": {
          "movie": 46970 <a id="CO213-2"></a><i class="conum" data-value="2"></i>
        }
      }
    }
  },
  "aggs": {
    "most_popular": {
      "terms": {
        "field": "movie", <a id="CO213-3"></a><i class="conum" data-value="3"></i>
        "size": 6
      }
    }
  }
}</pre>
</div>
<div class="sense_widget" data-snippet="snippets/300_Aggregations/75_sigterms.json"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO213-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>We execute our query on <code class="literal">mlratings</code> this time, and set the <code class="literal">size</code> to 0
since we are interested only in the aggregation results.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO213-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>Apply a filter on the ID corresponding to <em>Talladega Nights</em>.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO213-3"><i class="conum" data-value="3"></i></a></p>
</td>
<td align="left" valign="top">
<p>Finally, find the most popular movies by using a <code class="literal">terms</code> bucket.</p>
</td>
</tr>
</table>
</div>
<p>We perform the search on the <code class="literal">mlratings</code> index, and apply a filter for the ID of
<em>Talladega Nights</em>.  Since aggregations operate on query scope, this will
effectively filter the aggregation results to only the users who recommended
<em>Talladega Nights</em>. Finally, we execute a <code class="literal">terms</code> aggregation to bucket the most
popular movies.  We are requesting the top six results, since it is likely
that <em>Talladega Nights</em> itself will be returned as a hit (and we don’t want
to recommend the same movie).</p>
<p>The results come back like so:</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
...
   "aggregations": {
      "most_popular": {
         "buckets": [
            {
               "key": 46970,
               "key_as_string": "46970",
               "doc_count": 271
            },
            {
               "key": 2571,
               "key_as_string": "2571",
               "doc_count": 197
            },
            {
               "key": 318,
               "key_as_string": "318",
               "doc_count": 196
            },
            {
               "key": 296,
               "key_as_string": "296",
               "doc_count": 183
            },
            {
               "key": 2959,
               "key_as_string": "2959",
               "doc_count": 183
            },
            {
               "key": 260,
               "key_as_string": "260",
               "doc_count": 90
            }
         ]
      }
   }
...</pre>
</div>
<p>We need to correlate these back to their original titles, which can be done
with a simple filtered query:</p>
<div class="pre_wrapper lang-sense">
<pre class="programlisting prettyprint lang-sense">GET mlmovies/_search
{
  "query": {
    "filtered": {
      "filter": {
        "ids": {
          "values": [2571,318,296,2959,260]
        }
      }
    }
  }
}</pre>
</div>
<div class="sense_widget" data-snippet="snippets/300_Aggregations/75_sigterms.json"></div>
<p>And finally, we end up with the following list:</p>
<div class="olist orderedlist">
<ol class="orderedlist">
<li class="listitem">
Matrix, The
</li>
<li class="listitem">
Shawshank Redemption
</li>
<li class="listitem">
Pulp Fiction
</li>
<li class="listitem">
Fight Club
</li>
<li class="listitem">
Star Wars Episode IV: A New Hope
</li>
</ol>
</div>
<p>OK—​well that is certainly a good list!  I like all of those movies.  But that’s
the problem: most <em>everyone</em> likes that list.  Those movies are universally
well-liked, which means they are popular on everyone’s recommendations.  The
list is basically a recommendation of popular movies, not recommendations related
to <em>Talladega Nights</em>.</p>
<p>This is easily verified by running the aggregation again, but without the filter
on <em>Talladega Nights</em>.  This will give a top-five most popular movie list:</p>
<div class="pre_wrapper lang-sense">
<pre class="programlisting prettyprint lang-sense">GET mlratings/_search
{
  "size" : 0,
  "aggs": {
    "most_popular": {
      "terms": {
        "field": "movie",
        "size": 5
      }
    }
  }
}</pre>
</div>
<div class="sense_widget" data-snippet="snippets/300_Aggregations/75_sigterms.json"></div>
<p>This returns a list that is very similar:</p>
<div class="olist orderedlist">
<ol class="orderedlist">
<li class="listitem">
Shawshank Redemption
</li>
<li class="listitem">
Silence of the Lambs, The
</li>
<li class="listitem">
Pulp Fiction
</li>
<li class="listitem">
Forrest Gump
</li>
<li class="listitem">
Star Wars Episode IV: A New Hope
</li>
</ol>
</div>
<p>Clearly, just checking the most popular movies is not sufficient to build a good,
discriminating recommender.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="_recommending_based_on_statistics"></a>Recommending Based on Statistics<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch-definitive-guide/edit/2.x/300_Aggregations/75_sigterms.asciidoc">edit</a>
</h3>
</div></div></div>
<p>Now that the scene is set, let’s try using <code class="literal">significant_terms</code>.  <code class="literal">significant_terms</code> will analyze
the group of people who enjoy <em>Talladega Nights</em> (the <em>foreground</em> group) and
determine what movies are most popular.  It will then construct a list of
popular films for everyone (the <em>background</em> group) and compare the two.</p>
<p>The statistical anomalies will be the movies that are <em>over-represented</em> in the
foreground compared to the background.  Theoretically, this should be a list
of comedies, since people who enjoy Will Ferrell comedies will recommend them
at a higher rate than the background population of people.</p>
<p>Let’s give it a shot:</p>
<div class="pre_wrapper lang-sense">
<pre class="programlisting prettyprint lang-sense">GET mlratings/_search
{
  "size" : 0,
  "query": {
    "filtered": {
      "filter": {
        "term": {
          "movie": 46970
        }
      }
    }
  },
  "aggs": {
    "most_sig": {
      "significant_terms": { <a id="CO214-1"></a><i class="conum" data-value="1"></i>
        "field": "movie",
        "size": 6
      }
    }
  }
}</pre>
</div>
<div class="sense_widget" data-snippet="snippets/300_Aggregations/75_sigterms.json"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO214-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>The setup is nearly identical — we just use <code class="literal">significant_terms</code> instead of
<code class="literal">terms</code>.</p>
</td>
</tr>
</table>
</div>
<p>As you can see, the query is nearly the same.  We filter for users who
liked <em>Talladega Nights</em>; this forms the foreground group.  By default,
<code class="literal">significant_terms</code> will use the entire index as the background, so we don’t need to do
anything special.</p>
<p>The results come back as a list of buckets similar to <code class="literal">terms</code>, but with some
extra metadata:</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">...
   "aggregations": {
      "most_sig": {
         "doc_count": 271, <a id="CO215-1"></a><i class="conum" data-value="1"></i>
         "buckets": [
            {
               "key": 46970,
               "key_as_string": "46970",
               "doc_count": 271,
               "score": 256.549815498155,
               "bg_count": 271
            },
            {
               "key": 52245, <a id="CO215-2"></a><i class="conum" data-value="2"></i>
               "key_as_string": "52245",
               "doc_count": 59, <a id="CO215-3"></a><i class="conum" data-value="3"></i>
               "score": 17.66462367106966,
               "bg_count": 185 <a id="CO215-4"></a><i class="conum" data-value="4"></i>
            },
            {
               "key": 8641,
               "key_as_string": "8641",
               "doc_count": 107,
               "score": 13.884387742677438,
               "bg_count": 762
            },
            {
               "key": 58156,
               "key_as_string": "58156",
               "doc_count": 17,
               "score": 9.746428133759462,
               "bg_count": 28
            },
            {
               "key": 52973,
               "key_as_string": "52973",
               "doc_count": 95,
               "score": 9.65770100311672,
               "bg_count": 857
            },
            {
               "key": 35836,
               "key_as_string": "35836",
               "doc_count": 128,
               "score": 9.199001116457955,
               "bg_count": 1610
            }
         ]
 ...</pre>
</div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO215-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>The top-level <code class="literal">doc_count</code> shows the number of docs in the foreground group.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO215-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>Each bucket lists the key (for example, movie ID) being aggregated.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO215-3"><i class="conum" data-value="3"></i></a></p>
</td>
<td align="left" valign="top">
<p>A <code class="literal">doc_count</code> for that bucket.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO215-4"><i class="conum" data-value="4"></i></a></p>
</td>
<td align="left" valign="top">
<p>And a background count, which shows the rate at which this value appears in
the entire background.</p>
</td>
</tr>
</table>
</div>
<p>You can see that the first bucket we get back is <em>Talladega Nights</em>.  It is
found in all 271 documents, which is not surprising.  Let’s look at the next bucket:
key <code class="literal">52245</code>.</p>
<p>This ID corresponds to <em>Blades of Glory</em>, a comedy about male figure skating
that also stars Will Ferrell.  We can see that it was recommended 59 times by
the people who also liked <em>Talladega Nights</em>.  This means that 21% of the foreground
group recommended <em>Blades of Glory</em> (<code class="literal">59 / 271 = 0.2177</code>).</p>
<p>In contrast, <em>Blades of Glory</em> was recommended only 185 times in the entire dataset,
which equates to a mere 0.26% (<code class="literal">185 / 69796 = 0.00265</code>).  <em>Blades of Glory</em> is therefore
a statistical anomaly: it is uncommonly common in the group of people who
like <em>Talladega Nights</em>.  We just found a good recommendation!</p>
<p>If we look at the entire list, they are all comedies that would fit as good
recommendations (many of which also star Will Ferrell):</p>
<div class="olist orderedlist">
<ol class="orderedlist">
<li class="listitem">
Blades of Glory
</li>
<li class="listitem">
Anchorman: The Legend of Ron Burgundy
</li>
<li class="listitem">
Semi-Pro
</li>
<li class="listitem">
Knocked Up
</li>
<li class="listitem">
40-Year-Old Virgin, The
</li>
</ol>
</div>
<p>This is just one example of the power of <code class="literal">significant_terms</code>. Once you start using
<code class="literal">significant_terms</code>, you find many situations where you don’t want the most popular—​you want the most uncommonly common.  This simple aggregation can uncover some
surprisingly sophisticated trends in your data.</p>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="significant-terms.html">« Significant Terms</a>
</span>
<span class="next">
<a href="docvalues-and-fielddata.html">Doc Values and Fielddata »</a>
</span>
</div>
</div>

                  <!-- end body -->
                </div>
                <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                  <div id="rtpcontainer" style="display: block;">
                    <div class="mktg-promo">
                      <h3>Most Popular</h3>
                      <ul class="icons">
                        <li class="icon-elasticsearch-white"><a href="https://www.elastic.co/webinars/getting-started-elasticsearch?baymax=default&amp;elektra=docs&amp;storm=top-video">Get Started with Elasticsearch: Video</a></li>
                        <li class="icon-kibana-white"><a href="https://www.elastic.co/webinars/getting-started-kibana?baymax=default&amp;elektra=docs&amp;storm=top-video">Intro to Kibana: Video</a></li>
                        <li class="icon-logstash-white"><a href="https://www.elastic.co/webinars/introduction-elk-stack?baymax=default&amp;elektra=docs&amp;storm=top-video">ELK for Logs &amp; Metrics: Video</a></li>
                      </ul>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </section>

        </div>


<div id="elastic-footer"></div>
<script src="https://www.elastic.co/elastic-footer.js"></script>
<!-- Footer Section end-->

      </section>
    </div>

<script src="/guide/static/jquery.js"></script>
<script type="text/javascript" src="/guide/static/docs.js"></script>
<script type="text/javascript">
  window.initial_state = {}</script>
  </body>
</html>
